#include <iostream>

using namespace std;

int main()
{
    #include <iostream>
#include <unordered_map>
#include <cmath>
#include <vector>
#include <sstream>

using namespace std;

string wo(const string& word) {
    unordered_map<string, string> words = {
        {"zero", "0"},
        {"one", "1"},
        {"two", "2"},
        {"three", "3"},
        {"four", "4"},
        {"five", "5"},
        {"six", "6"},
        {"seven", "7"},
        {"eight", "8"},
        {"nine", "9"}
    };
    auto it = words.find(word);
    if (it != words.end()) {
        return it->second;
    }
    return "";
}

bool s(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(sqrt(n)); ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    string input;
    getline(cin, input);
    istringstream iss(input);
    vector<string> put;
    string word;
    while (iss >> word) {
        put.push_back(word);
    }

    if (put.size() != 3) {
        cout << "Wrong input" << endl;
    } else {
        string n;
        for (const auto& w : put) {
            n += wo(w);
        }
        if (n.length() != 3 || !all_of(n.begin(), n.end(), ::isdigit)) {
            cout << "Wrong input" << endl;
        } else {
            int number = stoi(n);
            int lp = -1;
            int up = -1;
            int i = 1;
            while (true) {
                if (number - i >= 0 && s(number - i)) {
                    lp = number - i;
                    break;
                }
                if (s(number + i)) {
                    up = number + i;
                    break;
                }
                ++i;
            }

            if (lp != -1) {
                cout << lp << endl;
            } else if (up != -1) {
                cout << up << endl;
            }
        }
    }

